(function() {
    var Event = Laya.Event;
    var SoundManager = Laya.SoundManager;
    var SOUNDSTATUS = Arena.SOUNDSTATUS;

    /**
     * 声音按钮扩展
     * 
     * @param {Laya.View} UI 声音按钮的UI界面
     */
    function BtnSound(wrap, UI, callback) {
        this.UI = UI;
        this.callback = callback;

        SOUNDSTATUS.CURRENT = status || SOUNDSTATUS.CURRENT;
        this.init();

        (wrap || UI).on(Event.CLICK, this, function () {
            switch(SOUNDSTATUS.CURRENT){
                case SOUNDSTATUS.ENABLE:
                    this.disable();

                    SoundManager.musicMuted = true;
                    SoundManager.soundMuted = true;

                    SoundManager.stopAll();

                    SOUNDSTATUS.BGMPLAY = false;
                    break;
                case SOUNDSTATUS.DISABLE:
                    this.enable();

                    SoundManager.musicMuted = false;
                    SoundManager.soundMuted = false;

                    SoundManager.playMusic("sound/bgm.mp3");

                    SOUNDSTATUS.BGMPLAY = true;
                    break;
            }
            
            this.callback && this.callback(SOUNDSTATUS.CURRENT);
            utils.log("点击了声音按钮，声音状态:" + (SOUNDSTATUS.CURRENT == SOUNDSTATUS.ENABLE ? "启用，1" : "禁用，0") );
        });
    }
    Laya.class(BtnSound, "ui.Com.BtnSound");

    var _proto = BtnSound.prototype;
    /**
     * @privite
     * 初始化声音状态
     */
    _proto.init = function (status) {
        switch(SOUNDSTATUS.CURRENT){
            case SOUNDSTATUS.DISABLE:
                this.disable();
                break;
            case SOUNDSTATUS.ENABLE:
            default:
                this.enable();

                if(!SOUNDSTATUS.BGMPLAY){
                    SoundManager.playMusic("sound/bgm.mp3");
                    SOUNDSTATUS.BGMPLAY = true;
                }
                break;
        }
        this.callback && this.callback(SOUNDSTATUS.CURRENT);
    }
    /**
     * @privite
     * 开启声音
     */
    _proto.enable = function () {
        this.UI.UIEnable.visible    = true;
        this.UI.UIAnimation.visible = true;
        this.UI.UIDisable.visible   = false;
        SOUNDSTATUS.CURRENT = SOUNDSTATUS.ENABLE;
    }
    /**
     * @privite
     * 关闭声音
     */
    _proto.disable = function () {
        this.UI.UIEnable.visible    = false;
        this.UI.UIAnimation.visible = false;
        this.UI.UIDisable.visible   = true;
        SOUNDSTATUS.CURRENT = SOUNDSTATUS.DISABLE;
    }
})();